using System;
using System.IO;

namespace ldapAccountGen
{
    /// <summary>
    /// Summary description for Instructors.
    /// </summary>
    public class Logger
    {
        // Get Project Settings
        private Properties.Settings settings = Properties.Settings.Default;
        private string fileName;
        private string eLogFile;
        private string logPath;

        public string FileName
        {
            set { fileName = value; }
            get { return fileName; }
        }
        public string ELogFile
        {
            set { eLogFile = value; }
            get { return eLogFile; }
        }
        public string LogPath
        {
            set { logPath = value; }
            get { return logPath; }
        }
        public void create()
        {
            this.logPathFind();
            FileStream afs = new FileStream(this.logPath + this.fileName, FileMode.CreateNew);
            afs.Close();
            if (File.Exists(this.logPath + this.eLogFile))
            {
                Console.WriteLine("Error log exists, appending to it.");
            }
            else
            {
                FileStream efs = new FileStream(this.logPath + this.eLogFile, FileMode.CreateNew);
                efs.Close();
            }
        }
        public void write(string textline, string type)
        {
            string timeStamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
            Console.WriteLine(textline);

            string fname = this.fileName;
            if (type == "ERROR")
            {
                fname = this.eLogFile;
                textline = "[" + timeStamp + "] " + textline;
            }
            StreamWriter w = File.AppendText(this.logPath + fname);
            w.WriteLine(textline);
            w.Flush();
            w.Close();
        }
        public void logPathFind()
        {
            if (settings.OS == "linux")
            {
                this.LogPath = "/var/log/SAG/";
            }
            else
            {
                this.LogPath = @"C:\temp\logs\";
            }
        }
    }
}
